package com.shensi.api.admin.domian.customer.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.shensi.common.core.annotation.Excel;
import com.shensi.common.core.domain.BaseEntity;
import com.shensi.common.core.utils.MathUtil;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 客户电子会员卡（储蓄卡）对象 customer_electronic_card
 *
 * @author qujia
 * @date 2021-04-12
 */

public class CustomerElectronicCardDto extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    private Long id;

    /**
     * 微信用户唯一标识unionId
     */
    @Excel(name = "微信用户唯一标识unionId")
    private String unionId;
    /**
     * 会员编号
     */
    @Excel(name = "会员编号")
    private String customerNo;

    /**
     * 客户名
     */
    @Excel(name = "客户名")
    private String customerName;

    /**
     * 用户手机号
     */
    @Excel(name = "用户手机号")
    private String mobilePhone;

    /**
     * 电子储蓄卡余额
     */
    @Excel(name = "电子储蓄卡余额")
    private BigDecimal amt;

    //赠送金额
    private BigDecimal presentAmt;

    /**
     * 电子会员卡类型：1，汽油；2.柴油；
     */
    @Excel(name = "电子会员卡类型：1，汽油；2.柴油；")
    private String cardOilsType;

    /**
     * 存的是油企ID，单站使用时不为空
     */
    @Excel(name = "油站ID")
    @Deprecated
    private Long stationId;
    private Integer num;

    /**
     * 油站名称
     */
    @Excel(name = "油站名称")
    private String stationName;

    /**
     * 最近使用时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "最近使用时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date recentlyTime;

    @Excel(name = "充值金额")
    private BigDecimal czamt;
    @Excel(name = "消费金额")
    private BigDecimal xfamt;
    @Excel(name = "电子会员数量")
    private BigDecimal cardnum;
    @Excel(name = "累计余额")
    private BigDecimal cumamt;
    @Excel(name = "累计电子会员数量")
    private BigDecimal cumnum;

    private Integer pageSetting;
    private Integer pageNo;
    private String strSql;

    private BigDecimal PresentAmt;


    //汽油卡余额
    private BigDecimal qyAmt;
    //柴油卡余额
    private BigDecimal cyAmt;
    //LNG余额
    private BigDecimal LNGAmt;
    //CNG余额
    private BigDecimal CNGAmt;


    /**
     * 油站ID
     */
    @Excel(name = "油企ID")
    private Long enterpriseId;

    /**
     * 存的是油站ID，单站使用时不为空
     */
    private Long stationId2;

    private BigDecimal totalAmt;

    /**
     * 入参须为正数
     *
     * @param amount
     * @return
     */
    public ElectronicCardSubResDto subtractAmount(BigDecimal amount) {
        ElectronicCardSubResDto res = ElectronicCardSubResDto.newInstance();
        if (amount == null) {
            res.setSuccess(false);
            return res;
        }
        if (amount.compareTo(BigDecimal.ZERO) == 0) {
            res.setSuccess(true);
            return res;
        }
        BigDecimal totalAmt = MathUtil.add(this.amt, this.presentAmt);
        if (totalAmt.compareTo(amount) < 0) {
            res.setSuccess(false);
            return res;
        }
        if (this.amt != null) {
            BigDecimal newAmt = this.amt.subtract(amount);
            if (newAmt.compareTo(BigDecimal.ZERO) < 0) {
                res.setAmt(this.amt);
                this.amt = BigDecimal.ZERO;
                this.presentAmt = this.presentAmt.add(newAmt);
                res.setPresentAmt(newAmt.abs());
            } else {
                res.setAmt(amount);
                this.amt = newAmt;
            }
        } else {
            this.presentAmt = this.presentAmt.subtract(amount);
            res.setPresentAmt(amount);
        }
        res.setSuccess(true);
        return res;
    }

    public BigDecimal getTotalAmt() {
        return totalAmt;
    }

    public void setTotalAmt(BigDecimal totalAmt) {
        this.totalAmt = totalAmt;
    }

    public BigDecimal getPresentAmt() {
        return presentAmt;
    }

    public void setPresentAmt(BigDecimal presentAmt) {
        this.presentAmt = presentAmt;
    }

    @JsonIgnore
    private String[] cardOilsTypeArray;

    public BigDecimal getQyAmt() {
        return qyAmt;
    }

    public void setQyAmt(BigDecimal qyAmt) {
        this.qyAmt = qyAmt;
    }

    public BigDecimal getCyAmt() {
        return cyAmt;
    }

    public void setCyAmt(BigDecimal cyAmt) {
        this.cyAmt = cyAmt;
    }

    public BigDecimal getLNGAmt() {
        return LNGAmt;
    }

    public void setLNGAmt(BigDecimal LNGAmt) {
        this.LNGAmt = LNGAmt;
    }

    public BigDecimal getCNGAmt() {
        return CNGAmt;
    }

    public void setCNGAmt(BigDecimal CNGAmt) {
        this.CNGAmt = CNGAmt;
    }

    public Long getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(Long enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public String getStrSql() {
        return strSql;
    }

    public void setStrSql(String strSql) {
        this.strSql = strSql;
    }

    public Integer getPageSetting() {
        return pageSetting;
    }

    public void setPageSetting(Integer pageSetting) {
        this.pageSetting = pageSetting;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public BigDecimal getCzamt() {
        return czamt;
    }

    public void setCzamt(BigDecimal czamt) {
        this.czamt = czamt;
    }

    public BigDecimal getXfamt() {
        return xfamt;
    }

    public void setXfamt(BigDecimal xfamt) {
        this.xfamt = xfamt;
    }

    public BigDecimal getCardnum() {
        return cardnum;
    }

    public void setCardnum(BigDecimal cardnum) {
        this.cardnum = cardnum;
    }

    public BigDecimal getCumamt() {
        return cumamt;
    }

    public void setCumamt(BigDecimal cumamt) {
        this.cumamt = cumamt;
    }

    public BigDecimal getCumnum() {
        return cumnum;
    }

    public void setCumnum(BigDecimal cumnum) {
        this.cumnum = cumnum;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setUnionId(String unionId) {
        this.unionId = unionId;
    }

    public String getUnionId() {
        return unionId;
    }

    public void setCustomerNo(String customerNo) {
        this.customerNo = customerNo;
    }

    public String getCustomerNo() {
        return customerNo;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setMobilePhone(String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }

    public String getMobilePhone() {
        return mobilePhone;
    }

    public void setAmt(BigDecimal amt) {
        this.amt = amt;
    }

    public BigDecimal getAmt() {
        return amt;
    }

    public void setCardOilsType(String cardOilsType) {
        this.cardOilsType = cardOilsType;
    }

    public String getCardOilsType() {
        return cardOilsType;
    }

    public Long getStationId() {
        return stationId;
    }

    public void setStationId(Long stationId) {
        this.stationId = stationId;
    }

    public void setStationName(String stationName) {
        this.stationName = stationName;
    }

    public String getStationName() {
        return stationName;
    }

    public void setRecentlyTime(Date recentlyTime) {
        this.recentlyTime = recentlyTime;
    }

    public Date getRecentlyTime() {
        return recentlyTime;
    }

    public Long getStationId2() {
        return stationId2;
    }

    public void setStationId2(Long stationId2) {
        this.stationId2 = stationId2;
    }

    public String[] getCardOilsTypeArray() {
        return cardOilsTypeArray;
    }

    public void setCardOilsTypeArray(String[] cardOilsTypeArray) {
        this.cardOilsTypeArray = cardOilsTypeArray;
    }


    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", getId())
                .append("unionId", getUnionId())
                .append("customerNo", getCustomerNo())
                .append("customerName", getCustomerName())
                .append("mobilePhone", getMobilePhone())
                .append("amt", getAmt())
                .append("cardOilsType", getCardOilsType())
                .append("stationId", getStationId())
                .append("stationName", getStationName())
                .append("createTime", getCreateTime())
                .append("recentlyTime", getRecentlyTime())
                .toString();
    }
}
